﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Appcode;
using MyWeb.Business;
using MyWeb.Data;
using MyWeb.Common;

namespace MyWeb
{
    public partial class Cart1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadImgData();
                cartStep1.Visible = true;
              
              
            }
        }

        public void loadImgData()
        {
            List<Images> listCart = Session.GetShopingCart();

            GridView1.DataSource = listCart;

            GridView1.DataBind();
        }



        public String getTotalPriceByID(String _id)
        {
            List<Images> listCart = Session.GetShopingCart();
            float totalPrice = 0;

            for (int i = 0; i < listCart.Count; i++)
            {
                if (listCart[i].ImageID == Convert.ToInt32(_id))
                {
                    totalPrice = listCart[i].ImgQuantity * listCart[i].UnitPrice;
                    break;
                }
            }

            return totalPrice.ToString();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            loadImgData();
        }
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {


        }
       
        protected void btnBackAlbum_Click(object sender, EventArgs e)
        {
            Response.Redirect("AlbumManager1.aspx");
        }
        protected void btnupdate_Click(object sender, EventArgs e)
        {
            GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
            int index = gvRow.RowIndex;
            TextBox txtQuan = (TextBox)GridView1.Rows[index].FindControl("txtQuantity");
            int imgID = Convert.ToInt32(GridView1.DataKeys[index].Values[0].ToString());
            int quan = Convert.ToInt32(txtQuan.Text);

            List<Images> listCart = Session.GetShopingCart();

            for (int i = 0; i < listCart.Count; i++)
            {
                if (listCart[i].ImageID == imgID && quan > 0)
                {
                    listCart[i].ImgQuantity = quan;
                    break;
                }
            }

            Session.SetShopingCart(listCart);


        }
        protected void btnremove_Click(object sender, EventArgs e)
        {
        }

        protected void btnMakeOrder_Click(object sender, EventArgs e)
        {
            Response.Redirect("MakeOrder.aspx");
        }

     

        
    }
}